*** This file creates the event study parameter datasets with the first increase year as the first treatment year
*** Here we do not break states up into large, small and indexer categories. All increases are considered together 


*** Last updated: 12/6/2021

capture log close
set more off
clear all
* If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"

global dtadir "$path/Data"
global tabdir "$path/Tables"
global figdir "$path/Figures"
global estdir "$path/Estimates"
global logdir "$path/Logfiles"

log using "$logdir/event-studies-no-categories-include-no-covariates-drop-indexers.log", replace

*** Assemble relevant years of ACS 
use "$path/Data/ACS-2019.dta", clear

*** Drop seniors
drop if age >= 65 | age < 16
drop if empstat == 0

*** Construct economic outcomes of interest 
gen employed = 0
replace employed = 1 if  empstat == 1

gen inlaborforce = 0
replace inlaborforce = 1 if  labforce == 2

gen unemployed = 0
replace unemployed = 1 if inlaborforce == 1 & employed == 0

**** Construct education variables

gen dropout = 0 
replace dropout = 1 if educ < 6
gen highschool = 0 
replace highschool = 1 if educ == 6
gen somecollege = 0
replace somecollege = 1 if educ >= 7 & educ < 10
gen collegeplus = 0
replace collegeplus = 1 if educ >= 10

***
* Assign the policy categories
***

merge m:1 statefip using "$path/Data\min_wage_variables_for_ACS_and_CPS_analysis.dta"
drop _merge

drop statincreasebydec20*
drop statincreasebyjan20*

*** Fix weight variable
rename perwt cmpwgt

*** Generate year of First Increase or First Legislated Increase
gen year1 = year(date1)
gen legyear1 = year(legdate1)

*** Drop states that are only indexers and never changed to increasers during the sample (FL, MT, OH)
drop if statefip == 12 | statefip == 30 | statefip == 39

* Drop all indexer states
drop if indexer == 1

* Since we don't have 2020 data yet, put the states with first increases in 2020 or first legislation passed in 2019 into the never increased category
replace year1 =. if year1 == 2020
replace legyear1 =. if legyear1 == 2019

tab year1
tab legyear1

* First increase associated with new legislation
* For most states, this will be the year after a minimum wage increase is passed
* But some states, like DE, MI, MN, and OR passed and enacted an increase in the same calendar year.
gen legimpyear1 = legyear1
replace legimpyear1 = legyear1 + 1 if legyear1 !=. & !inlist(statefip,10,26,27,41)
replace legimpyear1 = legyear1 if inlist(statefip,10,26,27,41)

* Get cohorts for each increase type
levelsof year1, local(firstincreaseyear)
levelsof legyear1, local(firstlegyear)
levelsof legimpyear1, local(legimpyear)

gen inctimeNOI = year - legimpyear + 1
replace inctimeNOI = 999 if inctimeNOI > 2010

* Check year of first increase by state
tab state legimpyear1

* Check that eventtime is coded as 1 for the year of first increase
tab state year if inctimeNOI == 1

*** Create event dummies for all statutory increasers equal to 1 on the year of first increase
gen inctimeNOIneg4plus = inctimeNOI <= -4
gen inctimeNOIneg3plus = inctimeNOI <= -3
gen inctimeNOIneg2plus = inctimeNOI <= -2
gen inctimeNOIneg3 = inctimeNOI == -3
gen inctimeNOIneg2 = inctimeNOI == -2
gen inctimeNOIneg1 = inctimeNOI == -1
gen inctimeNOIzero = inctimeNOI == 0
gen inctimeNOIpos1 = inctimeNOI == 1
gen inctimeNOIpos2 = inctimeNOI == 2
gen inctimeNOIpos3 = inctimeNOI == 3
gen inctimeNOIpos2plus = inctimeNOI >= 2 & inctimeNOI != 999
gen inctimeNOIpos3plus = inctimeNOI >= 3 & inctimeNOI != 999
gen inctimeNOIpos4plus = inctimeNOI >= 4 & inctimeNOI != 999

*** Housing Index and Income Changes
merge m:1 statefip year using "$path/Data\HousingIndexChanges.dta"
keep if _merge == 3
drop _merge
merge m:1 statefip year using "$path/Data\PersonalIncomeChanges.dta"
keep if _merge == 3
drop _merge

capture drop sample serial hhwt pernum cluster metro met2013 strata gq sex race raced empstat ///
empstatd labforce occ1990 ind1990 wkswork2 uhrswork inctot incwage migrate1 ///
migrate1d migplac1 movedin hcovany hinsemp hinspur hcovpub hinscaid hinscare ///
D4HPI D4lnPersonalIncome stateempD jan*min change* mw_jan* mw_change*

compress

local eventtime inctimeNOIneg3plus inctimeNOIneg2 inctimeNOIneg1 inctimeNOIpos1 inctimeNOIpos2 inctimeNOIpos3 inctimeNOIpos4plus


*** Analyses of the Low-Skill and Young Groups with varying degrees of control for house prices, income, and past changes in house prices and income

* No controls low-skilled
reghdfe employed `eventtime' [aw = cmpwgt] if age <= 25 & dropout == 1 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTime/EventTimeRegressionEmploymentLeastNoControls.dta", replace)

* No controls young
reghdfe employed `eventtime' [aw = cmpwgt] if age <= 21 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTime/EventTimeRegressionEmploymentYoungNoControls.dta", replace)

* Base controls low-skilled
reghdfe employed `eventtime'  lnPersonalIncome HPI [aw = cmpwgt] if age <= 25 & dropout == 1 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTime/EventTimeRegressionEmploymentLeastBaseControls.dta", replace)

* Base controls young
reghdfe employed `eventtime' lnPersonalIncome HPI  [aw = cmpwgt] if age <= 21 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTime/EventTimeRegressionEmploymentYoungBaseControls.dta", replace)

* Rich controls low-skilled
reghdfe employed `eventtime' D3lnPersonalIncome D3HPI lnPersonalIncome HPI [aw = cmpwgt] if age <= 25 & dropout == 1 & (year >= 2010), absorb(statefip age educ year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTime/EventTimeRegressionEmploymentLeastRichControls.dta", replace)

* Rich controls young
reghdfe employed `eventtime' D3lnPersonalIncome D3HPI lnPersonalIncome HPI [aw = cmpwgt] if age <= 21 & (year >= 2010), absorb(statefip age educ year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTime/EventTimeRegressionEmploymentYoungRichControls.dta", replace)

log close
